package 算法;

import org.apache.ibatis.annotations.Param;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

//https://leetcode-cn.com/problems/product-of-array-except-self/
public class 除自身以外数组的乘积 {
    public static void main(String[] args) {
        int[] t = productExceptSelf(new int[]{1,2,3,4});
        System.out.println("s");
    }
    public static int[] productExceptSelf(int[] nums) {
        int leng = nums.length;
        int[] left = new int[leng];
        int[] right = new int[leng];
        int[] res = new int[leng];
        left[0] = 1;
        right[leng-1] = 1;
        for (int i = 1; i < leng; i++) {
            left[i] = left[i-1]*nums[i-1];
            right[leng-i-1] = right[leng-i]*nums[leng-i];
        }
        for (int i = 0; i < res.length; i++) {
            res[i] = left[i]*right[i];
        }
        return res;
    }
}
